import CharacterDTO from "../pojo/dto/CharacterDTO";
import SkillDTO from "../pojo/dto/SkillDTO";
import CharacterPO from "../pojo/po/CharacterPO";
import SkillPO from "../pojo/po/SkillPO";
import CharacterVO from "../pojo/vo/CharacterVO";
import SkillVO from "../pojo/vo/SkillVO";
import SkillManageSingle from "./SkillManageSingle";

/*****************************
 *@file: HeroEntity
 *@author: 陈吕唐
 *@desc: 英雄实体类 (最完整的英雄数据包括英雄的技能数据穿戴的装备,但是不包括战斗逻辑)
 *@date: 2024-03-22	11:16
 *****************************/
export default class CharacterEntity implements CharacterVO {
    /****************************************************************************************************************
     *Readonly 常量
     ****************************************************************************************************************/

    /****************************************************************************************************************
     *Property 定义变量
     ****************************************************************************************************************/
    private _id: number;

    private _name: string;

    private _hp: number;

    private _atk: number;

    private _def: number;

    private _spd: number;

    private _moveSpeed: number;

    private _scope: number;

    private _skillIds: number[];

    private _lv: number;

    /**
     * 当前技能数据
     */
    public skills: SkillVO[] = [];
    /***************************************************************
     *PO
     ***************************************************************/
    private po: CharacterPO = undefined!;
    /***************************************************************
     *PropertyUI 引用的控件
     ***************************************************************/

    /****************************************************************************************************************
     * Lifecycle 生命周期相关方法
     ****************************************************************************************************************/
    public constructor(vo: CharacterVO) {
        this._id = vo.id;
        this._name = vo.name;
        this._hp = vo.hp;
        this._atk = vo.atk;
        this._def = vo.def;
        this._spd = vo.spd;
        this._scope = vo.scope;
        this._moveSpeed = vo.moveSpeed;
        this._skillIds = vo.skillIds;
        this._lv = vo.lv;
        this.po = vo;
        this.updateDTO(vo);
    }
    /****************************************************************************************************************
     * Public 公有方法
     ****************************************************************************************************************/
    public updateDTO(dto: CharacterDTO) {
        this._lv = dto.lv;

        this.updateAttribute(dto);
        this.updateSkill(dto);
    }
    /****************************************************************************************************************
     * private 私有方法
     ****************************************************************************************************************/
    /**
     * 更新属性数据
     * @param dto 
     */
    private updateAttribute(dto: CharacterDTO) {
        let lv = dto.lv;

        let po: CharacterPO = this.po;
        this._hp = po.hp * lv;
        this._atk = po.atk * lv;
        this._def = po.def * lv;
        this._spd = po.spd * lv;
        // this._moveSpeed = po.moveSpeed * lv;
        // this.updateAttribute(dto);
    }
    /**
     * 更新技能数据
     * @param dto 
     */
    private updateSkill(dto: CharacterDTO) {
        let lv = dto.lv;
        /**
         * 更新技能数据
         */
        let skill: SkillVO[] = [];
        for (let i = 0; i < lv; i++) {

            if (i >= this.skillIds.length) {
                continue;
            }

            let skillId = this.skillIds[i];
            let po: SkillPO = SkillManageSingle.single.getSkillPO(skillId);
            let dto: SkillDTO = { id: skillId, lv: lv };
            let vo: SkillVO = { ...dto, ...po };

            skill.push(vo);
        }
        this.skills = skill;
    }
    /****************************************************************************************************************
     * Property Get && Set 属性的 get && set 函数
     ****************************************************************************************************************/
    public get id(): number {
        return this._id;
    }
    public set id(value: number) {
        this._id = value;
    }
    public get name(): string {
        return this._name;
    }
    public set name(value: string) {
        this._name = value;
    }
    public get hp(): number {
        return this._hp;
    }
    public set hp(value: number) {
        this._hp = value;
    }
    public get atk(): number {
        return this._atk;
    }
    public set atk(value: number) {
        this._atk = value;
    }
    public get def(): number {
        return this._def;
    }
    public set def(value: number) {
        this._def = value;
    }
    public get spd(): number {
        return this._spd;
    }
    public set spd(value: number) {
        this._spd = value;
    }
    public get moveSpeed(): number {
        return this._moveSpeed;
    }
    public set moveSpeed(value: number) {
        this._moveSpeed = value;
    }
    public get scope(): number {
        return this._scope;
    }
    public set scope(value: number) {
        this._scope = value;
    }
    public get skillIds(): number[] {
        return this._skillIds;
    }
    public set skillIds(value: number[]) {
        this._skillIds = value;
    }
    public get lv(): number {
        return this._lv;
    }
    public set lv(value: number) {
        this._lv = value;
    }
}